home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-19 | 2.5 KB | 80 lines | [TEXT/MPS ] |
- /*
- File: TPrioritySchedulerExample.cp
-
- Contains: This module shows an example of the TPriorityScheduler class.
-
- Copyright: © 1993 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #include "TInitSLM.h" // the TInitSLM class and SLM include files
- #include "TSchedulerExample.h"
-
- ///————————————————————————————————————————————————————————————————————————————————————
- /// CONSTANTS
- ///————————————————————————————————————————————————————————————————————————————————————
-
- const unsigned kNumofStudents = 8; // no. of students
-
-
- ///————————————————————————————————————————————————————————————————————————————————————
- /// GLOBALS
- ///————————————————————————————————————————————————————————————————————————————————————
-
- // array of student names
- char *gStudents[kNumofStudents] ={"John Sculley",
- "Jane Doe ",
- "Bill Clinton",
- "George Bush ",
- "Mick Jagger ",
- "Ren & Stimpy",
- "Joe Montana ",
- "Al Einstein "};
-
- // grades for the above students
- Grade gGrades[kNumofStudents] ={kB, kA, kC, kF, kA, kD, kB, kB};
-
- /*————————————————————————————————————————————————————————————————————————————————————
- main
-
- This example schedules a list of student to be displayed depending to their grades.
- First it creates a TPriorityScheduler, then for each students it schedules a
- TReport operation. This operation. once invoked, displays the students name and
- his/her grade. The operations are executed in order of priority with the priority
- being based on the student's grade.
- ————————————————————————————————————————————————————————————————————————————————————*/
-
- main()
- {
- TInitSLM initLibraryManager; // initialize the shared library manager
-
- if( initLibraryManager.Failed() ) // If we failed, let go home
- return 1;
-
- TReport *thereport[kNumofStudents];
- TPriorityScheduler *reportScheduler;
-
- reportScheduler = new TPriorityScheduler;// create our priority Scheduler
-
- // for each student schedule a TOperation to report the grade
- for( short i=0; i<kNumofStudents; i++ ) {
- thereport[i] = new TReport;
- thereport[i]->NewStudent( gStudents[i] );
- thereport[i]->SetGrade( gGrades[i] );
-
- // now setup the priority for this operation
- thereport[i]->SetPriority( gGrades[i]+kNormalPriority );
-
- reportScheduler->Schedule( thereport[i] );
- }
-
- cout<< "Report cards prioritized depending on student's grade\n" << endl;
-
- reportScheduler->Run(); // process all the operations
-
- delete reportScheduler; // by now we should be done
-
- return 0;
- }
-
-